const express = require('express');
const router = express.Router();
const ollama = require('ollama');

router.get('/distribution', async (req, res) => {
    try {
        const courses = [
            { name: '学习', hours: 10 },
            { name: '娱乐', hours: 5 },
            { name: '运动', hours: 2 },
        ];

        const prompt = `Analyze the following data and provide a summary:
        ${JSON.stringify(courses)}`;
        const result = await ollama.analyze(prompt);

        res.json(result);
    } catch (error) {
        console.error('Error fetching distribution:', error);
        res.status(500).json({ error: '无法获取时间分布数据' });
    }
});

module.exports = router;
